<%--
  Created by IntelliJ IDEA.
  User: 84361
  Date: 2020/6/8
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>角色新增</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
</head>
<body>
<%--layui-form  layui的表单样式，添加到form表单上--%>
<form class="layui-form" >
    <div class="layui-form-item">
    <label class="layui-form-label">账号</label>
    <%--layui-input-inline 行内 block 占整行--%>
    <div class="layui-input-inline">
        <input name="account" type="text"  placeholder="请输入账号" autocomplete="off" class="layui-input">
    </div>
    </div>

    <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <%--layui-input-inline 行内 block 占整行--%>
    <div class="layui-input-inline">
        <input name="password" type="password"  placeholder="请输入密码" autocomplete="off" class="layui-input" >
    </div>
    </div>
    <%--一个表单项--%>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <%--layui-input-inline 行内 block 占整行--%>
        <div class="layui-input-inline">
            <input type="text" name="real_name" lay-verify="required" placeholder="请输入真实姓名" autocomplete="off" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-inline">
            <input lay-verify="phone" type="text" name="phone_number" lay-verify="required" placeholder="请输入手机号码" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电子邮箱</label>
        <div class="layui-input-inline">
            <input lay-verify="email" type="text" name="email" lay-verify="required" placeholder="请输入电子邮箱" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-inline">
            <select name="role_id" id="r" >
                <option value=""></option>
                <c:forEach items="${sessionScope.roles}" var="role">
                    <option value="${role.id}">${role.name}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item" >
        <%--lay-submit 标识该按钮可以提交表单--%>
        <input type="button" style="margin-left: 100px" lay-filter="add" lay-submit class="layui-btn" value="提交">
    </div>
</form>
<%--引入js--%>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>

    //layui引入特定模块的方式
    layui.use(['layer', 'form','jquery'], function () {
        var layer = layui.layer//layer 弹窗对象
            , form = layui.form;//表单对象
        var $=layui.$;

        layer.msg('Hello World');
        //表单提交监听
        form.on("submit(add)",function (data) {
            //发起异步请求，新增
            $.post("${pageContext.request.contextPath}/users/add",data.field,function (result) {
                if(result.code==0){
                    layer.msg("新增成功")
                    //刷新父窗口的表格
                    parent.layui.table.reload("roleTable",{
                        page:{
                            curr:1
                        }
                    })
                    //关闭本窗口
                    //当你在iframe页面关闭自身时
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }else if(result.code==403){
                    window.location.href="/403.jsp";
                }
            },"json")
            return false;
        })
    });
</script>
</body>
</html>
